import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'


const routes: Array<RouteRecordRaw> = [

  {
    path: '/',
    name: 'Login',
   
    component: () => import(/* webpackChunkName: "Login" */ '../views/Login/index.vue')
  },
  {
    path: '/reg',
    name: 'Reg',
   
    component: () => import(/* webpackChunkName: "Reg" */ '../views/Reg/index.vue')
  },
  {
    path: '/layout',
    name: 'Layout',
   
    component: () => import(/* webpackChunkName: "Layout" */ '../views/Layout/index.vue'),
    children:[{
      path: '/layout/',
      name: 'Home',
     
      component: () => import(/* webpackChunkName: "Home" */ '../views/Home/index.vue')
    },{
      path: '/layout/list',
      name: 'List',
     
      component: () => import(/* webpackChunkName: "List" */ '../views/List/index.vue')
    },{
      path: '/layout/class',
      name: 'Class',
     
      component: () => import(/* webpackChunkName: "Class" */ '../views/Class/index.vue')
    },{
      path: '/layout/my',
      name: 'My',
     
      component: () => import(/* webpackChunkName: "My" */ '../views/My/index.vue')
    },{
      path: '/layout/one',
      name: 'One',
     
      component: () => import(/* webpackChunkName: "One" */ '../views/One/index.vue')
    },{
      path: '/layout/two',
      name: 'Two',
     
      component: () => import(/* webpackChunkName: "Two" */ '../views/Two/index.vue')
    },{
      path: '/layout/three',
      name: 'Three',
     
      component: () => import(/* webpackChunkName: "Three" */ '../views/Three/index.vue')
    },{
      path: '/layout/for',
      name: 'For',
     
      component: () => import(/* webpackChunkName: "For" */ '../views/For/index.vue')
    },{
      path: '/layout/red',
      name: 'Red',
     
      component: () => import(/* webpackChunkName: "Red" */ '../views/Red/index.vue')
    },{
      path: '/layout/green',
      name: 'Green',
     
      component: () => import(/* webpackChunkName: "Green" */ '../views/Green/index.vue')
    },{
      path: '/layout/book',
      name: 'Book',
     
      component: () => import(/* webpackChunkName: "Book" */ '../views/Book/index.vue')
    },{
      path: '/layout/pop',
      name: 'Pop',
     
      component: () => import(/* webpackChunkName: "Pop" */ '../views/Pop/index.vue')
    },{
      path: '/layout/blue',
      name: 'Blue',
     
      component: () => import(/* webpackChunkName: "Blue" */ '../views/Blue/index.vue')
    },{
      path: '/layout/black',
      name: 'Black',
     
      component: () => import(/* webpackChunkName: "Black" */ '../views/Black/index.vue')
    }]
  },
  {
    path: '/detail',
    name: 'Detail',
   
    component: () => import(/* webpackChunkName: "Detail" */ '../views/Detail/index.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
// 路由拦截
router.beforeEach((to,from,next)=>{
  const token=localStorage.getItem('token')
  if(!token&&to.path!=='/'&&to.path!==('/reg')){
     next('/'),next('/reg')
  }else{
    next()
  }
})

export default router
